package com.syp.test.clustercacheflush.scheduled.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.syp.test.clustercacheflush.domain.TaskEntity;
import com.syp.test.clustercacheflush.scheduled.GeneralCronScheduled;
import com.syp.test.clustercacheflush.service.TaskService;
import com.syp.test.clustercacheflush.util.Constants;

import lombok.extern.slf4j.Slf4j;

/**
 * 解锁重试任务Scheduled,该Scheduled一直处于运行状态
 * 
 * @author syp
 */
@Slf4j
@Component
public class TaskRetryUnlockScheduled implements GeneralCronScheduled {

	@Autowired
	private TaskService taskService;

	@Scheduled(cron = Constants.CRON_EVERY_2_SECONDS)
	@Override
	public void dispatch() {
		List<TaskEntity> processList = this.taskService.getRetryFailureTask();
		if (processList != null && !processList.isEmpty()) {
			int influenceCount = this.taskService.unlock(processList);
			log.debug("解锁重试任务数量：{}", influenceCount);
		}
	}
}
